<template>
  <div>
    <div style="margin-top: 60%">
      <van-cell-group>
        <van-cell title="抗原检测记录" is-link @click="ifDetectionDataHave()"/>
        <van-cell title="个人信息设置" style="margin-top: 15%" is-link @click="routerHelper('setting')"/>
        <van-cell title="退出登录" style="margin-top: 15%" is-link @click="exit"/>
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import {Toast} from "vant";
export default {
  name: 'IndividualHome',
  data() {
    return {
      identity: '',
    }
  },
  mounted() {
    this.getUserIdentity();
  },
  methods: {

    getUserIdentity(){
      var userInfo = JSON.parse(localStorage.getItem("userInfo"));
      this.identity = userInfo.identity;
    },

	  // 退出登录
    exit() {
		   // 清除token和登录状态
		  localStorage.removeItem("token")
		  localStorage.removeItem("isLogin")
      localStorage.removeItem("userInfo")
		  // 跳转回登录页
		  this.$router.push({
			  path: `/`
		  })
    },

    routerHelper(arg) {
      this.$router.push('/' + arg)
    },

    // 判断用户是否有检测记录
    ifDetectionDataHave(){
      this.$axios(
          {
            method: "post",
            url: "http://localhost:8085/detection/ifDetectionDataHave",
            data: {
              identity: this.identity
            }
          }
      ).then(res => {
        if (res.data.code === 200) {
          let judge = res.data.data;
          if (judge > 0){
            this.routerHelper('detectionRecord');
          }
          else {
            Toast({
              message: '您暂时没有任何抗原检测记录',
              duration: 3000
            });
          }
        }
      })
    }
  }
}
</script>


